﻿#region 命名空间

using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WinnerCMS.Model;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.Template
{
    [Access("263001,263003")]
    public partial class Add : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["Action"] == "Edit")
                {
                    Title = "修改模板集";
                    this.lblPath2.Text = "<A href=\"Manage.aspx\">模板集管理</A> → 修改模板集";

                    var model = new TemplatesManage().GetInfo(Request["ID"]);

                    this.txtTemplateName.Text = model.TemplateName;
                    this.txtTemplatePath.Text = model.TemplatePath;
                    this.txtStyle.Text = model.Style;
                    this.txtRemark.Text = model.Remark;
                }
                else
                {
                    Title = "添加模板集";
                    this.lblPath2.Text = "<A href=\"Manage.aspx\">模板集管理</A> → 添加模板集";
                }
            }
        }

        private void AddUI()
        {
            var model = new WinnerCMS.Model.Template();
            model.TemplateName = this.txtTemplateName.Text.Trim();
            model.TemplatePath = this.txtTemplatePath.Text.Trim();

            model.Style = this.txtStyle.Text.Trim();
            model.Remark = this.txtRemark.Text.Trim();

            model.Id = Request["ID"];

            var res = new TemplatesManage().Add(model);

            if (string.IsNullOrEmpty(res.Errors) == false)
            {
                MsgBox.Message(res.Errors, this.UpdatePanel1);
            }
            else
            {
                Response.Redirect("Manage.aspx");
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            AddUI();
        }
    }
}